/* ver: 0.1, date 19-12-2007 by Jeroen W
 * added and implemented necessary public methods: 
 * getElement, clear, isCleared, getSizeX, getSizeY.
 * ver: 0.2, date 02-01-2007 by Marcel hekman
 * add clearSolveState
 * ver: 0.3, date 03-01-2007 by Marcel Hekman
 * bugfix: last rows are cleared as well now
 */
package mazeAssignment;


/**
 *
 * @author: jeroen, jeroen, marcel en teun
 */
public class DoubleArrayMaze implements Maze {

    private int xSize, ySize;
    private MazeElement[][] mazeGrid;
    
    //constructor that allows you to think of your own mazeconstruction.
    public DoubleArrayMaze(int x, int y)
    {
        mazeGrid= new MazeElement[x][y];
        for(int i=0; i<x; i++ )
        {
            for(int j=0; j<y; j++)
            {
            	 mazeGrid[i][j]= new MazeElement();
            }
        }
        xSize= x;
        ySize= y;
    }
    
    //returns element and sets cleared to false;
    private MazeElement getElement(int x, int y) {
    	return mazeGrid[x][y];
    }
    
    //clears array (and its elements)
    public void clear() {
        for(int i=0; i<mazeGrid.length; i++ )
        {
            for(int j=0; j<mazeGrid[i].length; j++)
            {
                mazeGrid[i][j].clear();
            }
        }
    }
    
    //clears the solve state for the array.
    public void clearSolveState()
    {
    	for(int i=0; i<mazeGrid.length; i++ )
        {
            for(int j=0; j<mazeGrid[i].length; j++)
            {
                mazeGrid[i][j].clearSolveState();
            }
        }
    }

    //returns x-size of maze
    public int getSizeX() {
        return xSize;
    }
    
    //returns y-size of maze
    public int getSizeY() {
       return ySize;
    }

	@Override
	public void visit(int x, int y) {
		getElement(x, y).visit();
	}

	@Override
	public void markAsInvalid(int x, int y) {
		getElement(x, y).markAsInvalid();
	}

	@Override
	public boolean isVisited(int x, int y) {
		return getElement(x, y).isVisited();
	}

	@Override
	public boolean getWest(int x, int y) {
		return getElement(x, y).getWest();
	}

	@Override
	public boolean getEast(int x, int y) {
		return getElement(x, y).getEast();
	}

	@Override
	public boolean getNorth(int x, int y) {
		return getElement(x, y).getNorth();
	}

	@Override
	public boolean getSouth(int x, int y) {
		return getElement(x, y).getSouth();
	}

	@Override
	public void setNorth(int x, int y, boolean state) {
		getElement(x, y).setNorth(state);
	}

	@Override
	public void setSouth(int x, int y, boolean state) {
		getElement(x, y).setSouth(state);
	}

	@Override
	public void setEast(int x, int y, boolean state) {
		getElement(x, y).setEast(state);
	}

	@Override
	public void setWest(int x, int y, boolean state) {
		getElement(x, y).setWest(state);
	}

	@Override
	public void setSolveState(int x, int y, int sState) {
		getElement(x, y).setSolveState(sState);
	}

	@Override
	public int getSolveState(int x, int y) {
		return getElement(x, y).getSolveState();
	}

	@Override
	public int getBuildState(int x, int y) {
		return getElement(x, y).getBuildState();
	}
}
